﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Text;
using Web.Models;
using System.Collections.Specialized;

namespace Web.ZebraUIControls
{
    public class ZebraQueryZone : ZebraDivZone
    {
        /// <summary>
        /// 输入控件，包含文本框，下拉框，单选框等控件
        /// </summary>
        public List<ZebraInputControl> InputControls { get; set; }
        /// <summary>
        /// 按钮控件和分隔符
        /// </summary>
        public List<ZebraButtonControl> ButtonControls { get; set; }
       /// <summary>
       /// 数据列表控件
       /// </summary>
        public ZebraDataList DataList { get; set; }
        /// <summary>
        /// 书否显示分页
        /// </summary>
        public ZebraPager Pager { get; set; } 


        public ZebraQueryZone()
        {
            //ShowBorder = true;
          
            //ShowSpliter = true;
        }

        public override void RenderControl(HtmlTextWriter writer)
        {
            //if(ShowBorder)
            RenderHeader(writer); //输出Header
            if (InputControls != null)
            {
                NameValueCollection queryEntityModel=html.ViewData["queryValues"] as NameValueCollection;
               
                foreach (var input in InputControls) //输出输入控件
                {
                    input.BizObjectType = BizObjectType;
                    if (null != queryEntityModel) 
                        input.Value = queryEntityModel[input.DataField];
                    input.html = html;
                    input.RenderControl(writer);
                    AppendScript(input.RenderControlScript());

                }
            }
            if (ButtonControls != null)//输出分隔符和按钮
            {
                foreach (var button in ButtonControls)
                {
                    button.html = html;
                    button.RenderControl(writer);
                    AppendScript(button.RenderControlScript());
                }
            }
            if (DataList != null && Pager != null)//输出网格控件
            {
                DataList.Pager = Pager;
            }

            if(DataList !=null)//输出网格控件
            {
                DataList.html = html;
                DataList.RenderControl(writer);
                AppendScript(DataList.RenderControlScript());

            }
            if (Pager != null)
            {
                Pager.html = html;
                Pager.RenderControl(writer);
                AppendScript(Pager.RenderControlScript());
            }
            //输出Footer
            RenderFooter(writer);

            //输出脚本
            if (ControlSricpts!=null)
            {
                writer.WriteLine("<script type='text/javascript'>");
                writer.Write(ControlSricpts.ToString());
                writer.WriteLine("</script>");
            }
        }
    }
}
